$(function () {
    $(window).scroll(function () {  //只要窗口滚动,就触发下面代码
        var scrollt = document.documentElement.scrollTop + document.body.scrollTop; //获取滚动后的高度
        if (scrollt > 10) {
            $("#back_top").fadeIn(400); //淡入
        } else {
            $("#back_top").stop().fadeOut(400); //如果返回或者没有超过,就淡出.必须加上stop()停止之前动画,否则会出现闪动
        }
    });
    $("#back_top").click(function () { //当点击标签的时候,使用animate在200毫秒的时间内,滚到顶部
        $("html,body").animate({scrollTop: "0px"}, 200);
    });
});
jQuery(function () {
    jQuery.post("search/tags",function (rst) {
        let trs='';
        for(let i=0;i<rst.length;i++)
        {
            let j=i+1;
            trs+=`
                    <tr>
                        <td><a href="/demo/tags/${j}" style="font-family: 楷体">${rst[i]}</a></td>
                    </tr>
            `;
        }
        jQuery("#tag").html(trs);
    })
})

jQuery(function () {
    jQuery.post("search", {"userId": -1, "blogId": -1}, function (rst) {
        let trs = '';
        var converter = new showdown.Converter(); //初始化转换器
        for (let i = 0; i < rst.length; i++) {
            let u = rst[i];
            var htmlcontent = u.content;
            if (u.blogFromOther == 'false') {
                htmlcontent = converter.makeHtml(u.content); //将MarkDown转为html格式的内容
            }
            let temp = "/" + "${u.userId}" + "/" + "${u.blogId}";
            let time = u.createDate;
            let pattern = /(\d{4})(\d{2})(\d{2})(\d{2})(\d{2})(\d{2})/;
            var createTime = time.replace(pattern, '$1/$2/$3');
            trs += `       
        <div class="first all">
            <div class="panel-body" style="margin-bottom: 5px">
                <div class="index-title">
                    <div class="title text-center text">
                        <a href="blog/${u.blogId}" class="header-title text">${u.blogTitle}</a>
                    </div>
                    
                </div>
                <hr style="margin: 0 0 10px 0;">
                <div class="file-content content hidden" style="max-height:50px">
                    ${htmlcontent}
                 </div>
                    <hr style="margin: 10px 0 0 0;">
                 <div style="text-align: right">
                    ${u.userInfo.userName}&nbsp;&nbsp;&nbsp;${createTime}
                 </div>
            </div>
        </div>
          `;
        }
        if (trs.length == 0) {
            trs = `
                <div  class="title text-center">没有数据</div>
                    `;
        }
        //把数据添加到tbody中
        jQuery("#adc").html(trs);
    })
});

jQuery(function () {
    jQuery("#btnSend").click(function () {
        let form = jQuery("#form").serialize();
        jQuery.post("/demo/email", form, function (rst) {
            alert(rst);
        });
    })
});
// jQuery(function () {
//     jQuery(".toblog").click(function(){
//         jQuery.post(href);
//     })
// });

